package com.youku.plugins.commonui.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import flash.utils.Timer;
   import com.youku.events.PlayerControlEvent;
   import flash.events.TimerEvent;
   import com.youku.events.PluginEvent;
   import flash.events.Event;
   
   public class PreVideoScreenMediator extends Object
   {
      
      public function PreVideoScreenMediator(param1:MovieClip, param2:IPlayerProxy) {
         super();
         this._mainMc = param1;
         this._playerProxy = param2;
         this._preVideoScreen = new PreVideoScreen();
         this.Init();
      }
      
      private var _mainMc:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _preVideoScreen:PreVideoScreen;
      
      private var _timer:Timer;
      
      private function Init() : void {
         this._playerProxy.addEventListener(PlayerControlEvent.SHOW_PRE_VIDEO_SCREEN,this.onPlayerEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.HIDE_PRE_VIDEO_SCREEN,this.onPlayerEvent);
         this.preVideoScreen.x = 0;
         this.preVideoScreen.y = 0;
         this._timer = new Timer(0 * 1000,1);
         this._timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimerComplete);
      }
      
      private function onTimerComplete(param1:TimerEvent) : void {
         this._timer.stop();
         this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PRE_VIDEO_SCREEN_COMPLETE));
      }
      
      private function get preVideoScreen() : PreVideoScreen {
         return this._preVideoScreen;
      }
      
      private function onPlayerEvent(param1:Event) : void {
         switch(param1.type)
         {
            case PlayerControlEvent.SHOW_PRE_VIDEO_SCREEN:
               this.show();
               break;
            case PlayerControlEvent.HIDE_PRE_VIDEO_SCREEN:
               this.hide();
               break;
         }
      }
      
      private function show() : void {
         if(!this._mainMc.contains(this.preVideoScreen))
         {
            this._mainMc.addChild(this.preVideoScreen);
         }
         this.preVideoScreen.visible = true;
         this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.PRE_VIDEO_SCREEN_COMPLETE));
      }
      
      private function hide() : void {
         if(this._mainMc.contains(this.preVideoScreen))
         {
            this._mainMc.removeChild(this.preVideoScreen);
         }
         this.preVideoScreen.visible = false;
      }
   }
}
